﻿<Framework:PageViewBase x:Class="DeSleeper.Client.Service.ServiceView"
    x:TypeArguments="Service:ServiceViewModel"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Installation="clr-namespace:DeSleeper.Client.Installation" 
    xmlns:Service="clr-namespace:DeSleeper.Client.Service"
    xmlns:Framework="clr-namespace:DeSleeper.Client.Framework;assembly=DeSleeper.Client.Framework"
    Title="Service Configuration"
    Name="_this"
    KeepAlive="True"
    VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
    Height="Auto" Width="Auto">
    <Page.Resources>
        <Service:InstallServiceParameters 
            x:Key="_installServiceParameter"
            IsInstalled="{Binding ElementName=_this, Path=IsInstalled}"
            SuppressCheckForDotNet="{Binding ElementName=suppressCheckForDotNet, Path=IsChecked}"
            PrecacheHostNamesString="{Binding ElementName=precacheHostNames, Path=Text}"
            InstallTargetsString="{Binding ElementName=remoteTargets, Path=Text}">
            <Service:InstallServiceParameters.Options>
                <Installation:InstallServiceOptions
                    LocalAddress="{Binding ElementName=localURI, Path=Text}"
                    ShouldRegisterWithMesh="{Binding ElementName=meshURI, Path=Text}"
                    MeshAddress="{Binding ElementName=registerWithMesh, Path=IsChecked}"/>
            </Service:InstallServiceParameters.Options>
        </Service:InstallServiceParameters>
        <Service:ConfigureTargetsParameters
            x:Key="_configureTargetsParameters"  
            EnableWakeOnLan="True"
            ConfigurePowerSettings="False"
            TargetsString="{Binding ElementName=precacheHostNames, Path=Text}"/>       
    </Page.Resources>
    <Grid Margin="12,0" >
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>

        <Label Grid.Row="0" Grid.Column="0" Name="meshURILabel">
            Mesh URI:
        </Label>
        <TextBox 
            Grid.Row="0" 
            Grid.Column="1" 
            Name="meshURI"
            Text="{Binding Source={StaticResource Settings}, Path=Default.DefaultMeshURI, Mode=TwoWay}" 
            IsEnabled="{Binding ElementName=registerWithMesh, Path=IsChecked}"/>
        <CheckBox Grid.Row="0" Grid.Column="2" Name="registerWithMesh">
            Register with mesh
        </CheckBox>

        <Label Grid.Row="1" Grid.Column="0" Name="localURILabel">
            Service URI:
        </Label>
        <TextBox 
            Grid.Row="1" 
            Grid.Column="1"
            Name="localURI"
            Text="{Binding Source={StaticResource Settings}, Path=Default.DefaultLocalServiceURI, Mode=TwoWay}" />

        <Label Grid.Row="2" Grid.Column="0" Name="remoteTargetsLabel">
            <TextBlock TextAlignment="Right">
               Install Remotely To:<LineBreak/><Italic>(Optional)</Italic>
            </TextBlock>
        </Label>
        <TextBox 
            Grid.Row="2" 
            Grid.Column="1"
            Name="remoteTargets"
            VerticalAlignment="Stretch"
            TextWrapping="WrapWithOverflow"
            Text="{Binding Source={StaticResource Settings}, Path=Default.RemoteServiceInstallTargets, Mode=TwoWay}" />
        <CheckBox Grid.Row="2" Grid.Column="2" Name="suppressCheckForDotNet">
            Suppress check for .NET
        </CheckBox>

        <Label Grid.Row="3" Grid.Column="0" Name="precacheLabel" Target="{Binding ElementName=precacheHostNames}">
            <TextBlock TextAlignment="Right">
                Precache Hosts:<LineBreak/><Italic>(Optional)</Italic>
            </TextBlock>
        </Label>
        <TextBox 
            Grid.Row="3"
            Grid.Column="1"
            VerticalAlignment="Stretch"
            TextWrapping="WrapWithOverflow"
            Name="precacheHostNames"
            ToolTip="Enter a comma seperated list of hosts you want to be able to wakeup by hostname, the associated MAC addesses will be stored."/>
        <Grid Grid.Row="4" Grid.ColumnSpan="3" Grid.IsSharedSizeScope="True">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" SharedSizeGroup="Buttons" />
                <ColumnDefinition Width="Auto" SharedSizeGroup="Buttons" />
                <ColumnDefinition Width="Auto" SharedSizeGroup="Buttons" />
            </Grid.ColumnDefinitions>
            <Button 
                Padding="20,1" Grid.Column="0"
                Name="installServiceButton"
                Command="{Binding ElementName=_this, Path=ViewModel.InstallServiceCommand}"
                CommandParameter="{StaticResource _installServiceParameter}">
                Install
            </Button>
            <Button 
                Padding="20,1" Grid.Column="1"
                Name="uninstallServiceButton"
                Command="{Binding ElementName=_this, Path=ViewModel.UninstallServiceCommand}"
                CommandParameter="{StaticResource _installServiceParameter}">
                Uninstall
            </Button>
            <Button 
                Padding="20,1" Grid.Column="2"
                Name="prepareTargets"
                Command="{Binding ElementName=_this, Path=ViewModel.ConfigureTargetsCommand}"
                CommandParameter="{StaticResource _configureTargetsParameters}"
                ToolTip="Enables Wake-On-Lan for all network cards of hosts entered into &quot;Precache Hosts&quot;">
                Prepare Hosts
            </Button>
        </Grid>
    </Grid>
</Framework:PageViewBase>